package com.zheng.redpacket.server.serivce.Impl;

import com.zheng.redpacket.mdg.mapper.UserMapper;
import com.zheng.redpacket.mdg.model.User;
import com.zheng.redpacket.server.dto.UserLoginDto;
import com.zheng.redpacket.server.serivce.SysLogService;
import com.zheng.redpacket.server.serivce.UserService;
import com.zheng.redpacket.server.utils.publisher.LoginPublisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserServiceImpl.class);

    @Resource
    private UserMapper userMapper;
    @Resource
    private LoginPublisher loginPublisher;

    @Override
    public Boolean login(UserLoginDto loginDto) {
        User user = userMapper.selectByUserNamePassword(loginDto.getUserName(), loginDto.getPassword());
        if (user != null) {
            //当前用户登录成功
            loginDto.setUserId(user.getId());
            loginPublisher.sendLogMsg(loginDto);
            return true;
        }else {
            return false;
        }
    }
}
